import{An as e,E as t,Jt as n,u as r,wn as i}from"./B2uw_jGT1oIxh7.js";import{Suggestion as a}from"./B-5Ka7WM1oIxh7.js";function o({editor:e,overrideSuggestionOptions:t,extensionName:n,char:r=`@`}){return{editor:e,char:r,pluginKey:new i,command:({editor:e,range:t,props:i})=>{var a;(e.view.state.selection.$to.nodeAfter?.text)?.startsWith(` `)&&(t.to+=1),e.chain().focus().insertContentAt(t,[{type:n,attrs:{...i,mentionSuggestionChar:r}},{type:`text`,text:` `}]).run(),(a=e.view.dom.ownerDocument.defaultView?.getSelection())==null||a.collapseToEnd()},allow:({state:e,range:t})=>{let r=e.doc.resolve(t.from),i=e.schema.nodes[n];return!!r.parent.type.contentMatch.matchType(i)},...t}}function s(e){return(e.options.suggestions.length?e.options.suggestions:[e.options.suggestion]).map(t=>o({editor:e.editor,overrideSuggestionOptions:t,extensionName:e.name,char:t.char}))}function c(e,t){let n=s(e);return n.find(e=>e.char===t)||(n.length?n[0]:null)}var l=r.create({name:`mention`,priority:101,addOptions(){return{HTMLAttributes:{},renderText({node:e,suggestion:t}){return`${t?.char??`@`}${e.attrs.label??e.attrs.id}`},deleteTriggerWithBackspace:!1,renderHTML({options:e,node:t,suggestion:r}){return[`span`,n(this.HTMLAttributes,e.HTMLAttributes),`${r?.char??`@`}${t.attrs.label??t.attrs.id}`]},suggestions:[],suggestion:{}}},group:`inline`,inline:!0,selectable:!1,atom:!0,addAttributes(){return{id:{default:null,parseHTML:e=>e.getAttribute(`data-id`),renderHTML:e=>e.id?{"data-id":e.id}:{}},label:{default:null,parseHTML:e=>e.getAttribute(`data-label`),renderHTML:e=>e.label?{"data-label":e.label}:{}},mentionSuggestionChar:{default:`@`,parseHTML:e=>e.getAttribute(`data-mention-suggestion-char`),renderHTML:e=>({"data-mention-suggestion-char":e.mentionSuggestionChar})}}},parseHTML(){return[{tag:`span[data-type="${this.name}"]`}]},renderHTML({node:e,HTMLAttributes:t}){let r=c(this,e.attrs.mentionSuggestionChar);if(this.options.renderLabel!==void 0)return console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),[`span`,n({"data-type":this.name},this.options.HTMLAttributes,t),this.options.renderLabel({options:this.options,node:e,suggestion:r})];let i={...this.options};i.HTMLAttributes=n({"data-type":this.name},this.options.HTMLAttributes,t);let a=this.options.renderHTML({options:i,node:e,suggestion:r});return typeof a==`string`?[`span`,n({"data-type":this.name},this.options.HTMLAttributes,t),a]:a},...t({nodeName:`mention`,name:`@`,selfClosing:!0,allowedAttributes:[`id`,`label`,{name:`mentionSuggestionChar`,skipIfDefault:`@`}],parseAttributes:e=>{let t={},n=/(\w+)=(?:"([^"]*)"|'([^']*)')/g,r=n.exec(e);for(;r!==null;){let[,i,a,o]=r;t[i===`char`?`mentionSuggestionChar`:i]=a??o,r=n.exec(e)}return t},serializeAttributes:e=>Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e===`mentionSuggestionChar`?`char`:e}="${t}"`).join(` `)}),renderText({node:e}){let t={options:this.options,node:e,suggestion:c(this,e.attrs.mentionSuggestionChar)};return this.options.renderLabel===void 0?this.options.renderText(t):(console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),this.options.renderLabel(t))},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.command(({tr:t,state:n})=>{let r=!1,{selection:i}=n,{empty:a,anchor:o}=i;if(!a)return!1;let s=new e,c=0;return n.doc.nodesBetween(o-1,o,(e,t)=>{if(e.type.name===this.name)return r=!0,s=e,c=t,!1}),r&&t.insertText(this.options.deleteTriggerWithBackspace?``:s.attrs.mentionSuggestionChar,c,c+s.nodeSize),r})}},addProseMirrorPlugins(){return s(this).map(a)}}),u=l;export{l as Mention,u as default};